
package com.yixiu.modules.db.datasources.service;


import com.yixiu.modules.db.datasources.DataSourceNames;
import com.yixiu.modules.db.datasources.DynamicDataSource;
import com.yixiu.modules.db.datasources.DynamicDataSourceConfig;
import com.yixiu.modules.db.datasources.annotation.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 测试多数据源
 *

 */
@Service
public class DataSourceTestService {

    @Autowired
    private   DynamicDataSource   dynamicDataSource;



    public  Map<String, Object> queryUser(){

        JdbcTemplate jdbcTemplate = new JdbcTemplate(dynamicDataSource);
        Map<String, Object> map = jdbcTemplate.queryForMap("select * from user limit 1" );  // 查询一行，并用Map返回
        return map;
    }

    @DataSource(name = DataSourceNames.SECOND)
    public  Map<String, Object> queryUser2( ){
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dynamicDataSource);
         Map<String, Object>  map = jdbcTemplate.queryForMap("select * from user limit 1", new Object[] {} );
        return map;
    }
}
